import Static from 'ol/source/ImageStatic';
import { Image } from 'ol/layer';

export const setImage = ({ url, bounds, imageExtent, zIndex }) => {
    const [a, b] = bounds || [];
    return new Image({
        zIndex,
        source: new Static({
            url,
            projection: 'EPSG:4326',
            imageExtent: imageExtent || [...a, ...b]
        }),
        draggable: true
    });
};

export function addCityImage(amap, layerCity) {
    const image = setImage({
        url: 'img/nb-dark2.png',
        bounds: [
            [120.86704099999997 - 0.21, 29.047449 - 0.5], // ['+（左侧）向右' '+（底部）向上']
            [122.14381800000001 + 0.328, 30.489772 + 0.109] // ['-（右侧）向左' '-（顶部）向下']
        ]
    });
    amap.addLayer(image);
}
// 区块激活
export function addAreaImage(amap) {
    const obj = {};

    obj['330213'] = setImage({
        url: 'img/fh-act.png',
        bounds: [
            [121.05091, 29.406342], // ['+（左侧）向右' '+（底部）向上']
            [121.780895, 29.787155] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 5
    });

    obj['330206'] = setImage({
        url: 'img/bl-act.png',
        bounds: [
            // [121.660777 - 0.03, 29.722435 - 0.04], // ['+（左侧）向右' '+（底部）向上']
            // [122.136104 + 0.04, 29.999799 - 0.01] // ['-（右侧）向左' '-（顶部）向下']
            [121.6527, 29.708935], // ['+（左侧）向右' '+（底部）向上']
            [122.158348, 29.990799] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 5
    });

    obj['330282'] = setImage({
        url: 'img/cx-act.png',
        bounds: [
            [121.04008, 30.038457], // ['+（左侧）向右' '+（底部）向上']
            [121.632636, 30.489772] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 5
    });

    obj['330281'] = setImage({
        url: 'img/yy-act.png',
        bounds: [
            [120.867041, 29.669728], // ['+（左侧）向右' '+（底部）向上']
            [121.425553, 30.352861] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 5
    });

    obj['330203'] = setImage({
        url: 'img/hs-act.png',
        bounds: [
            [121.139724, 29.724672], // ['+（左侧）向右' '+（底部）向上']
            [121.560949, 29.949712]
        ],
        zIndex: 5
    });

    obj['330205'] = setImage({
        url: 'img/jb-act.png',
        bounds: [
            [121.360701, 29.872435], // ['+（左侧）向右' '+（底部）向上']
            [121.645923, 30.056327] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 5
    });

    obj['330211'] = setImage({
        url: 'img/zz-act.png',
        bounds: [
            [121.466431, 29.894499], // ['+（左侧）向右' '+（底部）向上']
            [121.788392, 30.072124] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 5
    });

    obj['330212'] = setImage({
        url: 'img/yz-act.png',
        bounds: [
            [121.457535, 29.612658], // ['+（左侧）向右' '+（底部）向上']
            [121.895308, 29.90753] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 5
    });
    obj['330226'] = setImage({
        url: 'img/nh-act.png',
        bounds: [
            [121.158871, 29.091357], // ['+（左侧）向右' '+（底部）向上']
            [121.820317, 29.52119] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 5
    });
    obj['330225'] = setImage({
        url: 'img/xs-act.png',
        bounds: [
            [121.571977, 28.853304], // ['+（左侧）向右' '+（底部）向上']
            [122.268271, 29.655013] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 5
    });

    amap.addLayer(obj['330225']);
    amap.addLayer(obj['330226']);
    amap.addLayer(obj['330213']);
    amap.addLayer(obj['330206']);
    amap.addLayer(obj['330282']);
    amap.addLayer(obj['330281']);
    amap.addLayer(obj['330203']);
    amap.addLayer(obj['330205']);
    amap.addLayer(obj['330211']);
    amap.addLayer(obj['330212']);

    Object.keys(obj).forEach(key => {
        obj[key].setVisible(false);
    });

    return obj;
}
export function addAreaImagePoint(amap) {
    const obj = {};

    obj['330213'] = setImage({
        url: 'img/fh-act.png',
        bounds: [
            [120.70565868262518, 29.20038914772704], // ['+（左侧）向右' '+（底部）向上']
            [120.93633249086652, 29.506859714495484] // ['-（右侧）向左' '-（顶部）向下']
        ]
    });

    obj['330206'] = setImage({
        url: 'img/bl-act.png',
        bounds: [
            // [121.660777 - 0.03, 29.722435 - 0.04], // ['+（左侧）向右' '+（底部）向上']
            // [122.136104 + 0.04, 29.999799 - 0.01] // ['-（右侧）向左' '-（顶部）向下']
            [121.6527, 29.708935], // ['+（左侧）向右' '+（底部）向上']
            [122.158348, 29.990799] // ['-（右侧）向左' '-（顶部）向下']
        ],
        zIndex: 10
    });

    obj['330282'] = setImage({
        // url: 'img/cx-act.png',
        bounds: [
            [121.04008, 30.038457], // ['+（左侧）向右' '+（底部）向上']
            [121.632636, 30.489772] // ['-（右侧）向左' '-（顶部）向下']
        ]
    });

    obj['330281'] = setImage({
        url: 'img/yy.png',
        bounds: [
            [120.882731 - 0.035, 29.697032 - 0.05], // ['+（左侧）向右' '+（底部）向上']
            [121.390832 + 0.055, 30.376594 - 0.01] // ['-（右侧）向左' '-（顶部）向下']
        ]
    });

    obj['330203'] = setImage({
        url: 'img/hs.png',
        bounds: [
            [121.147689 - 0.03, 29.743435 - 0.042], // ['+（左侧）向右' '+（底部）向上']
            [121.544153 + 0.038, 29.965618] // ['-（右侧）向左' '-（顶部）向下']
        ]
    });

    obj['330205'] = setImage({
        url: 'img/jb.png',
        bounds: [
            [121.367439 - 0.025, 29.877223 - 0.027], // ['+（左侧）向右' '+（底部）向上']
            [121.63795 + 0.025, 30.066975 + 0.005] // ['-（右侧）向左' '-（顶部）向下']
        ]
    });

    obj['330211'] = setImage({
        url: 'img/zz.png',
        bounds: [
            [121.473515 - 0.027, 29.892596 - 0.022], // ['+（左侧）向右' '+（底部）向上']
            [121.788054 + 0.017, 30.087406 - 0.002] // ['-（右侧）向左' '-（顶部）向下']
        ]
    });

    obj['330212'] = setImage({
        url: 'img/yz.png',
        bounds: [
            [121.446408 - 0.005, 29.596866 - 0.01], // ['+（左侧）向右' '+（底部）向上']
            [121.875362 + 0.036, 29.94717 - 0.025] // ['-（右侧）向左' '-（顶部）向下']
        ]
    });

    amap.addLayer(obj['330213']);
    amap.addLayer(obj['330206']);
    amap.addLayer(obj['330282']);
    amap.addLayer(obj['330281']);
    amap.addLayer(obj['330203']);
    amap.addLayer(obj['330205']);
    amap.addLayer(obj['330211']);
    amap.addLayer(obj['330212']);

    Object.keys(obj).forEach(key => {
        obj[key].setVisible(true);
    });

    return obj;
}
